/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tmq.diancan.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tmq.diancan.entity.Menu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tmq.diancan.entity.DiancanProductCategory;
import com.tmq.diancan.vo.DiancanProductCategoryVO;
import com.tmq.diancan.service.IDiancanProductCategoryService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


/**
 * 类目表 控制器
 *
 * @author tangmqb
 * @since 2020-01-09
 */
@RestController
@AllArgsConstructor
@RequestMapping("/diancanproductcategory")
@Api(value = "类目表", tags = "类目表接口")
public class DiancanProductCategoryController {

	private IDiancanProductCategoryService
			diancanProductCategoryService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入diancanProductCategory")
	public R<DiancanProductCategory> detail(DiancanProductCategory diancanProductCategory) {
		LambdaQueryWrapper<DiancanProductCategory> eq = Wrappers.<DiancanProductCategory>query().lambda().eq(DiancanProductCategory::getCategoryId, diancanProductCategory.getCategoryId());
		DiancanProductCategory detail = diancanProductCategoryService.getOne(eq);
		return R.data(detail);
	}

	/**
	 * 分页 类目表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入diancanProductCategory")
	public R<IPage<DiancanProductCategory>> list(@ApiIgnore @RequestParam Map<String, Object> stringObjectMap, Query query) {
		IPage<DiancanProductCategory> pages = diancanProductCategoryService.page(Condition.getPage(query), Condition.getQueryWrapper(stringObjectMap, DiancanProductCategory.class).lambda().orderByAsc(DiancanProductCategory::getCategorySort));
		return R.data(pages);
	}
	/**
	 * 查询生效类目
	 */
	@GetMapping("/listCategory")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入diancanProductCategory")
	public R<List<DiancanProductCategory>> list(@ApiIgnore @RequestParam Map<String, Object> stringObjectMap) {
		stringObjectMap.put("isDeleted", 0);
		List<DiancanProductCategory> list = diancanProductCategoryService.list(Condition.getQueryWrapper(stringObjectMap, DiancanProductCategory.class).lambda().orderByAsc(DiancanProductCategory::getCategorySort));
		return R.data(list);
	}

	/**
	 * 自定义分页 类目表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入diancanProductCategory")
	public R<IPage<DiancanProductCategoryVO>> page(DiancanProductCategoryVO diancanProductCategory, Query query) {
		IPage<DiancanProductCategoryVO> pages = diancanProductCategoryService.selectDiancanProductCategoryPage(Condition.getPage(query), diancanProductCategory);
		return R.data(pages);
	}

	/**
	 * 新增 类目表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入diancanProductCategory")
	public R save(@Valid @RequestBody DiancanProductCategory diancanProductCategory) {
		return R.status(diancanProductCategoryService.save(diancanProductCategory));
	}

	/**
	 * 修改 类目表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入diancanProductCategory")
	public R update(@Valid @RequestBody DiancanProductCategory diancanProductCategory) {
		return R.status(diancanProductCategoryService.updateById(diancanProductCategory));
	}

	/**
	 * 新增或修改 类目表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入diancanProductCategory")
	public R submit(@Valid @RequestBody DiancanProductCategory diancanProductCategory) {
		return R.status(diancanProductCategoryService.saveOrUpdate(diancanProductCategory));
	}


	/**
	 * 删除 类目表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(diancanProductCategoryService.removeByIds(Func.toIntList(ids)));
	}


}
